import { createSlice } from '@reduxjs/toolkit'
const shoppingCartStore = createSlice({
    name:'footStore', // 仓库名称
    initialState:{    // 仓库数据
        footData:[],
        price:0
    },
    reducers:{   // 操作仓库数据  每个函数有两个参数  一个是仓库数据 state 一个是使用时候传来的数据action
        addFoots(state,action){
            console.log(action)
            
            state.footData.push(action.payload)
            state.price += +action.payload.price
        },

        deleteFoots(state,action){  
            state.footData.splice(state.footData.findIndex(item=>action.payload.id === item.id),1)
            state.price -= +action.payload.price
        },
    }
})

const {addFoots,deleteFoots} = shoppingCartStore.actions
const reducers = shoppingCartStore.reducer
export {addFoots,deleteFoots}
export default reducers